﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Runtime.InteropServices;   //호환되지 않은 Dll을 사용할때

namespace NH70_Debugger
{
    public partial class EncDec : Form
    {
        [DllImport("CBSeedHex.dll")]
        static extern int CBSeed_EncodeBlock_HexLp(IntPtr _IntPtr);
        static extern int CBSeed_DecodeBlock_HexLp(IntPtr _IntPtr);        

        public EncDec()
        {
            InitializeComponent();

        }

        private bool convertEnc(string sInData, ref string sOutData)
        {
            sOutData = sInData;
            IntPtr _IntPtr = Marshal.StringToBSTR(sOutData);
            CBSeed_EncodeBlock_HexLp(_IntPtr);

            return true;
        }

        private bool convertDec(string sInData, ref string sOutData)
        {

            sOutData = sInData;
            IntPtr _IntPtr = Marshal.StringToBSTR(sOutData);
            CBSeed_DecodeBlock_HexLp(_IntPtr);

            return true;
        }

        private void button_enc_Click(object sender, EventArgs e)
        {
            String sEncData, sInput = textBox_IN.Text;

            if (sInput.Length < 1)
                return;

            sEncData = "";

            convertEnc(sInput, ref sEncData);

            textBox_OUT.Text = sEncData;
        }

        private void button_dec_Click(object sender, EventArgs e)
        {
            String sDecData, sInput = textBox_IN.Text;

            if (sInput.Length < 1)
                return;

            sDecData = "";

            convertDec(sInput, ref sDecData);

            textBox_OUT.Text = sDecData;

        }
    }
}